# File：orm_test.py
# Author：信思智学
# Date ：2025/8/11 10:32
# Info：

import os
if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoORM20250807.settings")
    import django
    django.setup()
    from app.models import Book, Press, BookType
    from django.db.models import F,Q,Max,Min,Sum,Count,Avg

    #查询图书中价格的最大值和最小值
    # books = Book.objects.aggregate(Avg("bookprice"),Min("bookprice"))
    # print(books)

    # 分组 (默认分组)
    # books = Book.objects.annotate(Count("bookprice"))
    # print(books)

    result = Book.objects.values("press_id").annotate(num = Count("id")).values("press_id","num")
    print(result)










